//
//  RecommendTableViewCell.m
//  MeterMart
//
//  Created by ENERGY on 2018/9/18.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "RecommendTableViewCell.h"

@interface RecommendTableViewCell()
@property (nonatomic, strong)UIView * whiteBGView;
@property (nonatomic, strong)UIImageView * iconImg;
@property (nonatomic, strong)UILabel * titleLab;
@property (nonatomic, strong)UILabel * contentLab;
@property (nonatomic, strong)UILabel * moneyLab;
@property (nonatomic, strong)NSString * goodsID;
@end
@implementation RecommendTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = getColor(mainColor);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        __weak typeof (self)weakSelf = self;
        [self.contentView addSubview:self.whiteBGView];
        [self.whiteBGView addSubview:self.iconImg];
        [self.whiteBGView addSubview:self.titleLab];
        [self.whiteBGView addSubview:self.contentLab];
        [self.whiteBGView addSubview:self.moneyLab];
        [self.whiteBGView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.contentView.mas_left).mas_offset(6/WIDTH_6_SCALE);
            make.right.equalTo(weakSelf.contentView.mas_right).mas_offset(-6/WIDTH_6_SCALE);
            make.top.equalTo(weakSelf.contentView);
            make.bottom.equalTo(weakSelf.contentView.mas_bottom).mas_offset(-10/WIDTH_6_SCALE);
        }];
        [self.iconImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.whiteBGView.mas_left).mas_offset(15/WIDTH_6_SCALE);
            make.top.equalTo(weakSelf.whiteBGView.mas_top).mas_offset(17/WIDTH_6_SCALE);
            make.bottom.equalTo(weakSelf.whiteBGView.mas_bottom).mas_offset(-16/WIDTH_6_SCALE);
            make.width.mas_offset(130/WIDTH_6_SCALE);
        }];
        [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.iconImg.mas_right).mas_offset(11/WIDTH_6_SCALE);
            make.top.equalTo(weakSelf.iconImg);
            make.right.equalTo(weakSelf.whiteBGView.mas_right).mas_offset(-25/WIDTH_6_SCALE);
        }];
        [self.contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(weakSelf.titleLab);
            make.top.equalTo(weakSelf.titleLab.mas_bottom).mas_offset(5/WIDTH_6_SCALE);
        }];
        [self.moneyLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(weakSelf.titleLab);
            make.bottom.equalTo(weakSelf.whiteBGView.mas_bottom).mas_offset(-16/WIDTH_6_SCALE);
        }];
    }return self;
}

#pragma mark - init
- (UIView *)whiteBGView{
    if (!_whiteBGView) {
        _whiteBGView = [[UIView alloc] init];
        _whiteBGView.backgroundColor = [UIColor whiteColor];
    }return _whiteBGView;
}
- (UIImageView *)iconImg{
    if (!_iconImg) {
        _iconImg = [[UIImageView alloc] init];
        _iconImg.image = [UIImage imageNamed:@"YimiPlaceHolder"];
    }return _iconImg;
}
- (UILabel *)titleLab{
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.font = DEF_FontSize_16;
        _titleLab.textColor = [UIColor blackColor];
        _titleLab.textAlignment = NSTextAlignmentLeft;
        _titleLab.numberOfLines = 0;
        _titleLab.lineBreakMode = 0;
        _titleLab.text = @"￥ ---";
    }return _titleLab;
}
- (UILabel *)contentLab{
    if (!_contentLab) {
        _contentLab = [[UILabel alloc] init];
        _contentLab.font = DEF_FontSize_12;
        _contentLab.textColor = getColor(textGrayColor);
        _contentLab.textAlignment = NSTextAlignmentLeft;
        _contentLab.numberOfLines = 0;
        _contentLab.lineBreakMode = 0;
        _contentLab.text = @"￥ ---";
    }return _contentLab;
}
- (UILabel *)moneyLab{
    if (!_moneyLab) {
        _moneyLab = [[UILabel alloc] init];
        _moneyLab.font = DEF_FontSize_18;
        _moneyLab.textColor = [UIColor redColor];
        _moneyLab.textAlignment = NSTextAlignmentLeft;
        _moneyLab.text = @"￥ ---";
    }return _moneyLab;
}
- (void)setModel:(NSDictionary *)model{
    _model = model;
    [self.iconImg sd_setImageWithURL:[NSURL URLWithString:model[@"goodsimg"]] placeholderImage:[UIImage imageNamed:@"YimiPlaceHolder"]];
    self.titleLab.text = model[@"goodsname"];
    self.contentLab.text = model[@"goodsdescribe"];
    self.moneyLab.text = [NSString stringWithFormat:@"￥ %@", model[@"groupprice"]];
    self.goodsID = model[@"goodsid"];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
